Skip to content

added tests - #73

Merged
wpak-ai merged 6 commits into
cppalliance:mainfrom
jonathanMLDev:bugfix/add-tool-handler
May 14, 2026
Merged

added tests#73
wpak-ai merged 6 commits into
cppalliance:mainfrom
jonathanMLDev:bugfix/add-tool-handler

Conversation

@jonathanMLDev

@jonathanMLDev jonathanMLDev commented May 13, 2026

Copy link
Copy Markdown
Collaborator

Pull Request

Added

  • src/server/tools/test-helpers.ts — createMockServer(), parseToolJson(), makeSearchResult(), makeNamespaceCacheEntry().
  • src/server/tools/list-namespaces-tool.test.ts — 3 tests (happy path, cache_hit, cache error → generic getToolErrorMessage text).
  • src/server/tools/suggest-query-params-tool.test.ts — 4 tests (markSuggested when namespace exists, no mark when missing, empty query, cache failure).
  • src/server/tools/query-tool.test.ts — 6 tests for query, query_fast, and query_detailed registrations (this branch uses three tools, not a single preset field): happy paths, empty query, flow gate, TTL message, reranked: false passthrough.
  • src/server/tools/query-documents-tool.test.ts — 4 tests (happy path + mocked reassembleByDocument, empty query_text, flow gate, TTL).
  • src/server/tools/guided-query-tool.test.ts — 4 tests (query_detailed on content-style query, count override, empty user_query, no namespace).

Changed

  • vitest.config.ts— added 'lcov' to coverage.reporter.

Checks

  • npm run test — 61 tests passing (21 new in src/server/tools/*.test.ts).
  • npm run typecheck and npm run lint — clean.

Note:

Error-path assertions for thrown cache errors match the app’s getToolErrorMessage behavior (Failed to list namespaces / Failed to suggest query params), not the raw thrown message.

close #72

Summary by CodeRabbit

  • Tests
    • Added comprehensive test suites for query and namespace management tool handlers, covering success paths, error handling, and edge cases.
    • Added shared test helper utilities for streamlined MCP tool testing.
    • Enhanced test coverage reporting with LCOV format support.

Review Change Stack

@jonathanMLDev jonathanMLDev self-assigned this May 13, 2026
@jonathanMLDev jonathanMLDev added the enhancement New feature or request label May 13, 2026
@coderabbitai

coderabbitai Bot commented May 13, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@jonathanMLDev has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 19 minutes and 15 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 790f968c-800b-4e27-b1ad-3ff658f7c20e

📥 Commits

Reviewing files that changed from the base of the PR and between 893db16 and 742f5e0.

📒 Files selected for processing (4)
  • src/server/tools/guided-query-tool.test.ts
  • src/server/tools/query-documents-tool.test.ts
  • src/server/tools/query-tool.test.ts
  • src/server/tools/test-helpers.ts
📝 Walkthrough

Walkthrough

This PR adds comprehensive handler-level test coverage for five critical MCP tool handlers: query, query_documents, suggest_query_params, guided_query, and list_namespaces. It includes shared test utilities, validates happy paths and error conditions, and exercises edge cases like flow gating and TTL expiry. A vitest config update enables lcov coverage reporting.

Changes

MCP Tool Handler Test Suite

Layer / File(s) Summary
Test utilities and mock factories
src/server/tools/test-helpers.ts
Exports ToolHandler type, createMockServer() to record tool registrations, parseToolJson() to extract and parse response payloads, and factory functions makeSearchResult() and makeNamespaceCacheEntry() for constructing test fixtures.
Query tool handler tests
src/server/tools/query-tool.test.ts
Tests query and query_fast handlers with happy-path validation of client method calls, reranking flags, empty query rejection, flow context gating errors, TTL expiry detection, and rerank fallback with unreranked result preservation.
Query documents tool handler tests
src/server/tools/query-documents-tool.test.ts
Tests query_documents handler for topK capping, document reassembly invocation, empty query validation, flow gate failure when requireSuggested denies, and TTL expiration error messages.
Suggest query params tool handler tests
src/server/tools/suggest-query-params-tool.test.ts
Tests suggest_query_params handler validating success with namespace found and markSuggested invocation, success without marking when namespace absent, empty user_query rejection, and cache lookup error propagation.
Guided query tool handler tests
src/server/tools/guided-query-tool.test.ts
Tests guided_query handler routing logic: auto preferred_tool delegates to query_detailed, count preferred_tool calls the count operation, empty user_query rejection, and error when namespace resolution yields no available namespaces.
List namespaces tool handler tests
src/server/tools/list-namespaces-tool.test.ts
Tests list_namespaces handler success response with cache metadata shape, cache_hit propagation on warm cache, and error handling for cache lookup failures.
Test coverage configuration
vitest.config.ts
Vitest test.coverage.reporter expanded to include lcov format alongside existing text, json, and html reporters.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested reviewers

  • wpak-ai

🐰 Five tools now tested with care,
Mock servers record handlers' flair,
Happy paths and errors dance,
TTL expiry gets its chance—
Coverage blooms beyond compare!

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title 'added tests' is vague and generic, lacking specificity about which tools or what testing scope was added. Consider a more descriptive title such as 'Add handler-level tests for top 5 tools' or 'Add unit tests for query, suggest_query_params, and other tool handlers'.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed All 5 required tools (query, suggest_query_params, query_documents, guided_query, list_namespaces) have test coverage with 3+ test cases each, mocked client methods, and critical flow gates tested (requireSuggested, TTL expiry, reranking fallback).
Out of Scope Changes check ✅ Passed All changes are directly scoped to adding handler-level tests and test utilities; the vitest.config.ts change (lcov reporter) is a supporting infrastructure change for test coverage reporting.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/server/tools/guided-query-tool.test.ts`:
- Line 1: Prettier flagged formatting issues in the test file; run the project's
Prettier formatter on the file (e.g., `prettier --write`) or apply the repo's
formatting settings so the import line and surrounding spacing match the
configured style; ensure symbols like beforeEach, describe, expect, it, and vi
remain correctly imported and the file passes the CI style check.

In `@src/server/tools/query-documents-tool.test.ts`:
- Line 1: The file has Prettier style violations in the test imports (the line
importing afterEach, beforeEach, describe, expect, it, vi) and nearby
formatting; run the project's Prettier formatter (e.g., run prettier --write on
this test file) or apply the repo's formatting rules so the import line and
surrounding whitespace match the configured style; ensure the import list and
any trailing commas/spacing conform to the project's Prettier configuration.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: bf1310fa-d862-4e28-9f05-77a96931ee62

📥 Commits

Reviewing files that changed from the base of the PR and between 2b05008 and 893db16.

📒 Files selected for processing (7)
  • src/server/tools/guided-query-tool.test.ts
  • src/server/tools/list-namespaces-tool.test.ts
  • src/server/tools/query-documents-tool.test.ts
  • src/server/tools/query-tool.test.ts
  • src/server/tools/suggest-query-params-tool.test.ts
  • src/server/tools/test-helpers.ts
  • vitest.config.ts

Comment thread src/server/tools/guided-query-tool.test.ts
Comment thread src/server/tools/query-documents-tool.test.ts
@codecov

codecov Bot commented May 14, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.65217% with 1 line in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (main@c07279f). Learn more about missing BASE report.

Files with missing lines Patch % Lines
src/server/tools/test-helpers.ts 95.65% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main      #73   +/-   ##
=======================================
  Coverage        ?   52.68%           
=======================================
  Files           ?       30           
  Lines           ?     1118           
  Branches        ?      346           
=======================================
  Hits            ?      589           
  Misses          ?      529           
  Partials        ?        0           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@jonathanMLDev
jonathanMLDev requested a review from wpak-ai May 14, 2026 02:53
@wpak-ai
wpak-ai merged commit 335bda1 into cppalliance:main May 14, 2026
18 of 19 checks passed
@jonathanMLDev
jonathanMLDev deleted the bugfix/add-tool-handler branch May 18, 2026 17:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add MCP Tool Handler Tests for Top 5 Tools

2 participants